<?
if (!defined('IN_RJ')) die("Error 404");
if($cmd[1]=="movie" && is_numeric($cmd[2])){
$movie_id=$cmd[2];
$DB->query("update ".$conf['prefix']."multimedia set multi_viewed=multi_viewed+1,multi_viewed_month=multi_viewed_month+1 where multi_id={$movie_id} and multi_type=2");
$query="select * from ".$conf['prefix']."multimedia where multi_id={$movie_id} and multi_type=2";
$rq = $DB->query($query);
    if ($movie=$DB->fetch_row($rq)){
		$ro= $tpl->get_tpl('movie_detail');
        $cat_name =$func->get_data("cat",$movie['multi_cat']);
        $title = $func->unhtmlchars($movie["multi_name"]);
	     $title_ascii = $func->unhtmlchars($movie["multi_name_ascii"]);
		$multi_img=$func->get_img("multimedia",$movie_id,true);
		$director=($movie["multi_director"]!='')?$movie["multi_director"]:$lang['updating'];
		$actor=($movie["multi_actor"]!='')?$movie["multi_actor"]:$lang['updating'];
		$manufacturer=($movie["multi_manufacturer"]!='')?$movie["multi_manufacturer"]:$lang['updating'];
		$length=($movie["multi_length"]!='')?$movie["multi_length"]:$lang['updating'];
		$nation=($movie["multi_nation"]!='')?$movie["multi_nation"]:$lang['updating'];
		$date_produced=($movie["multi_date_produced"]!='')?$movie["multi_date_produced"]:$lang['updating'];
        $info =($movie["multi_info"]!='')?$func->unhtmlchars(stripslashes($movie["multi_info"])):$lang['updating'];
		$rate_img=$func->check_rate($movie["multi_rating"],$movie["multi_rating_total"]);
		if(preg_match("/ - /",$title_ascii)){
			$cut_search=explode(" - ",$title_ascii);
			$title_search=$cut_search[0];
		}
		else
			$title_search=$title_ascii;
			
			$ro = $tpl->assign_vars($ro,
				array(
					'movie.IMG'		=>	$multi_img,
					'movie.TITLE'	=>	$title,
					'movie.DIRECTOR'=> $director,
					'movie.ACTOR'	=> $actor,
					'movie.CAT'		=> $cat_name,
					'movie.CAT_URL'	=> $func->change_link("cat",$movie['multi_cat'],$func->title_2_ascii($cat_name,true)),
					'movie.MANUFACTURER' => $manufacturer,
					'movie.LENGTH'	=> $length,
					'movie.NATION'	=> $nation,
					'movie.DATE_PRODUCED' => $date_produced,
					'movie.INFO' => $info,
					'movie.VIEWED'	=> $movie['multi_viewed'],
					'movie.RATE_IMG' => $rate_img,
					'movie.ID'	=> $movie_id,
					'movie.SEARCH_OST' => $func->change_link("search",2,$title_search),//"<a href='".$func->change_link("album",2,$title_ascii)."'><img src='{TPL_LINK}/img/btn_nhacphim.gif' border=0></a>",
				)
			);
		
		$ro1= $tpl->get_tpl('movie_watch');
		$t['row'] = $tpl->get_block_from_str($ro1,'epi_row',1);
			$html='';
				if(is_numeric($cmd[3]))
			 	$current_epi=$cmd[3];
			if($current_epi){
				$sql_check_cur_server=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE m_multimedia={$movie_id} AND m_id={$current_epi} AND m_server>0");
				$result_cur_server=$DB->fetch_row($sql_check_cur_server);
			}
				$sql_check_server=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE m_multimedia={$movie_id} AND m_server>0");
				$result_check=$DB->num_rows($sql_check_server);
				preg_match_all("#<lserver>(.*?)</lserver>#",$conf['data_lserver'],$r);
				if($result_cur_server['m_server']>0)
					$html_server="<div id=\"server_0\" class=\"cl_server\"><a href=\"#\" onclick=\"return Load_server('0','{$movie_id}','".count($r[0])."');\"><b>Server 1</b></a></div>";
				else
					$html_server="<div id=\"server_0\" class=\"cl_server_cur\"><a href=\"#\" onclick=\"return Load_server('0','{$movie_id}','".count($r[0])."');\"><b>Server 1</b></a></div>";
					
				if(count($r[0])>0){
					for($i=0;$i<count($r[0]);$i++){
						preg_match("#<id>([0-9]+)</id>#",$r[1][$i],$match_id);
						preg_match("#<name>(.*?)</name>#",$r[1][$i],$match_name);
						if($result_check>0){
							if($match_id[1]==$result_cur_server['m_server'])
								$html_server.="&nbsp;&nbsp;&nbsp;<div id=\"server_".$match_id[1]."\" class=\"cl_server_cur\"><a href=\"#\" onclick=\"return Load_server('{$match_id[1]}','{$movie_id}','".count($r[0])."');\"><b>".$match_name[1]."</b></a></div>";
							else
								$html_server.="&nbsp;&nbsp;&nbsp;<div id=\"server_".$match_id[1]."\" class=\"cl_server\"><a href=\"#\" onclick=\"return Load_server('{$match_id[1]}','{$movie_id}','".count($r[0])."');\"><b>".$match_name[1]."</b></a></div>";
						}
					}
				}
			if($result_cur_server['m_server']>0)
				$sql_epi=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE m_multimedia={$movie_id} AND m_server={$result_cur_server['m_server']} ORDER BY CAST(m_title AS SIGNED)");
			else
				$sql_epi=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE m_multimedia={$movie_id} AND m_server=0 ORDER BY CAST(m_title AS SIGNED)");
			
			 $total_eps = $DB->num_rows($sql_epi);

				$show_epi_playing="";
			 if($conf['epi_noajax'] && $current_epi){
			 	/*$show_epi_playing.="<div style=\"background:#000000;\"><script type=\"text/javascript\">var marqueetext='Bạn đang xem phim <font color=\"#00FFFF\"><b>".$title."</b></font> tại Website 360Phim.Info, chúc bạn vui vẻ!';</script><script language=\"javascript1.2\" src=\"{$conf['web_url']}/js/slide_text.js\"></script></div>";*/
			 	$show_epi_playing.=$func->Get_player_epi($movie_id,$current_epi);
				}
			 else
			 	$show_epi_playing='<script type="text/javascript"><!--
google_ad_client = "pub-7869827443843863";
/* 360do 336x280, created 11/8/09 */
google_ad_slot = "0421717420";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
			 
			if($total_eps){
			$i = 0;
			$overflow=($total_eps>30)?'height:300px; overflow:auto;':'';
				while($epi=$DB->fetch_row($sql_epi)){
					$i++;
					$arr_epi[$i]['id']=$epi['m_id'];
					$arr_epi[$i]['title']=$epi['m_title'];
				  $tr = (fmod($i,5) == 1)?'<tr></tr>':'';	
				  if($current_epi && ($current_epi==$epi['m_id']))
				  	$class_cur_epi="cl_part_cur";
				  else
					$class_cur_epi="cl_part";
				  if($conf['epi_noajax'])
				  	$epi_div="<div id=\"epi_".$i."\" class=\"".$class_cur_epi."\" align=\"center\"><a href=\"".$func->change_link("movie_epi",$movie_id,"",$epi['m_id'])."\"><b>» ".$lang['part']." ".$epi['m_title']."</b></a></div>";
				  else
				  	$epi_div="<div id=\"epi_".$i."\" class=\"cl_part\" align=\"center\"><a href=\"#\" onclick=\"return Get_Player('".$movie_id."','".$epi['m_id']."','".$total_eps."','".$i."');\"><b>» ".$lang['part']." ".$epi['m_title']."</b></a></div>";
					$html .= $tpl->assign_vars($t['row'],
						array(
							'epi.TR'		=> $tr,
							'epi.DIV'		=> $epi_div,
						)
					);
				}
	
			if(!$conf['must_login_to_download'] || ($conf['must_login_to_download'] && $logged_in)){
				$download_block='<div style="width:240px; height:64px;" align="center">
						<form method="post" name="get_download_epi" onsubmit="get_download(this,\'epi\'); return false;">
						<b>'.$lang['choose_epi_down'].' </b><br />
						<select id="select_down" name="select_down">';
				foreach($arr_epi as $epi_d){
						$download_block.= "<option value='".$epi_d['id']."'>".$lang['part']." ".$epi_d['title']."</option>";
					 }
				$download_block.='</select>
						<input type="hidden" value="'.$func->encode_down($movie_id).'" id="id_down" name="id_down" />
						<input type="hidden" value="'.$movie_id.'" id="movie_id"  name="movie_id" />
						<input type="submit" value="Download" />
						</form>
						</div><br /><font color="red"><b>Nếu bạn không download được <a href="{WEB_URL}/huongdan_download.html" title="Click vào đây để xem hướng dẫn" target="_blank">Click vào đây để xem hướng dẫn</a></b>
</font>'; 
			}
			elseif($conf['must_login_to_download'] && !$logged_in) $download_block='<b>'.$lang['must_login_to_download'].'</b>';
		}
		else{
			$download_block='';
			$html="<center><font color=blue>".$lang['updating']."</font></center><br>";
		}
		
		
			$ro1 = $tpl->assign_blocks_content($ro1,array(
				'list_epi'	=> $html,
				'show_field_server' => $html_server,
				'download' => $download_block,
				'epi_noajax' => $show_epi_playing,
				)
			);
			$ro1 = $tpl->assign_vars($ro1,
				array(
					'movie.INFO' => $info,
					'movie.ID'	=> $movie_id,
					'movie.OVERFLOW'  =>$overflow,
					'movie.CAT_ID'		=> $movie['multi_cat'],
					'movie.URL_FULLSCREEN'	=> $func->change_link("moviefull",$movie_id,$func->title_2_ascii($title_ascii)),
				)
			);
		$jully=$ro.$ro1;
		}
		else $jully=box_announcement($lang['no_data']);
		$main_content=$jully;
		$title_web_bar=$title;
		$title_ascii_web_bar=$title_ascii;

}

elseif($cmd[1]=="album" && is_numeric($cmd[2])){
$album_id=$cmd[2];
if(!$cmd[3]) $cmd[3]=1;
$limit=($cmd[3]-1)*$conf['media_per_page'];
$DB->query("update ".$conf['prefix']."multimedia set multi_viewed=multi_viewed+1,multi_viewed_month=multi_viewed_month+1 where multi_id={$album_id} and multi_type=1");
$query=$DB->query("select * from {$conf['prefix']}multimedia where multi_id={$album_id} and multi_type=1");
	if(($album=$DB->fetch_row($query)) || $album_id==0){
		if($album_id==0){
			$album_name =$lang['unknown'];
			$album_name_ascii =$func->unhtmlchars($lang['unknown']);
			$album_info =$lang['updating'];
			$album['multi_cat']='';
			$album['multi_viewed']='';
			$singer_name=$lang['updating'];
			$album_relate='';
		}else{
			$album_name =$func->unhtmlchars($album['multi_name']);
			$album_name_ascii =$func->unhtmlchars($album['multi_name_ascii']);
			$album_info =($album["multi_info"]!='')?$func->unhtmlchars(stripslashes($album["multi_info"])):$lang['updating'];
			$singer_name=$func->get_data('singer',$album['multi_singer']);
			$album_relate=box_multimedia('Album_In_Cat',1, 9,$album['multi_cat'], 3,'',$album_id);
		}
		$album_img=$func->get_img("multimedia",$album_id,true);
		$ro_al= $tpl->get_tpl('album_detail');

		$t['row'] = $tpl->get_block_from_str($ro_al,'song_row',1);
		$html='';
		$sql_song=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE m_multimedia={$album_id} ORDER BY m_title_ascii DESC LIMIT {$limit},{$conf['media_per_page']}");
		$qr_tt=$DB->query("SELECT * FROM ".$conf['prefix']."media WHERE m_multimedia={$album_id}");
		$total_song = $DB->num_rows($qr_tt);
		if($total_song){
			$i=0;
			while($song=$DB->fetch_row($sql_song)){
				$i++;
				$html .= $tpl->assign_vars($t['row'],
					array(
						'song.TITLE'	=> $func->unhtmlchars($song['m_title']),
						'song.TYPE'		=> "<img src='{TPL_LINK}/".$func->get_data('player',$song['m_type'])."' border=0 >",
						'song.ID'		=> $song['m_id'],	
						'song.VIEWED'	=> $song['m_viewed'],
						'song.DOWNLOADED' => $song['m_downloaded'],
						'song.URL'		=> $func->change_link('song',$song['m_id'],$func->title_2_ascii($song['m_title_ascii'])),
						'song.ADD_PL'	=> $logged_in?"select_playlist({$song['m_id']});return false;":"guest_playlist({$song['m_id']});return false;",
					)
				);
				
			}
		}
		else $html="<center><font color=blue>".$lang['updating']."</font></center><br>";
			$ro_al = $tpl->assign_vars($ro_al,
				array(
					'album.NAME' => $album_name,
					'singer.NAME'=> $singer_name,
					'album.INFO' => $album_info,
					'album.ID'	=> $album_id,
					'album.CAT_ID'	=> $album['multi_cat'],
					'album.IMG' => $album_img,
					'album.VIEWED' => $album['multi_viewed'],
					'album.TOTAL'	=> $total_song,
					'album.RELATE'	=> $album_relate,
					'album.PAGES'  => $func->viewpages($total_song,$conf['media_per_page'],$cmd[3],$func->title_2_ascii($album_name_ascii)),	
				)
			);
			$ro_al = $tpl->assign_blocks_content($ro_al,array(
				'list_song'	=> $html,
				)
			);
	}
	else $ro_al=box_announcement($lang['no_data']);
		$main_content=$ro_al;
		$title_web_bar=$album_name;
		$title_ascii_web_bar=$album_name_ascii;
}
?>